package com.feng.controller;


import com.feng.entity.RestResponse;
import com.feng.exception.SystemException;
import com.feng.service.UploadService;
import com.feng.utils.HttpCodeEnum;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.imageio.IIOException;

@RestController
@RequestMapping("/api/upload")
public class UploadController {

    final
    UploadService uploadService;

    public UploadController(UploadService uploadService) {
        this.uploadService = uploadService;
    }

    @PostMapping
    public RestResponse upload(MultipartFile img){
        try {
            return uploadService.upload(img);
        }catch (Exception e){
            throw new SystemException(HttpCodeEnum.FILE_UPLOAD_ERROR);
        }
    }
}
